export const manyHander= {
  methods: {
    handelButton(event, val) {
      //批量操作
      if (event.action == 'assign') {
        let id = [];
        for (let k in val) {
          id.push(val[k].id);
        }
        id = id.join(',');
        if (!id) {
          this.$message({
            message: '未选择任何运单',
            type: 'warning'
          });
        } else {
          console.info('event.url',event.url);
          //批量功能提示语
          let msg='完成';
          if(event.url.includes('/dialog/cancel')){
            msg='取消'
          }else if(event.url.includes('/dialog/assign')){
            msg='指派'
          }else if (event.url.includes('/dialog/control')) {
              msg='接管'
          }
          this.$confirm(`确定要${msg}当前已选择运单?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            //若是完成，直接请求，其他跳转到请求路由
            if(event.url.includes('/dialog/complete')){
              this.$http.put('express/batch_complete_order?ids=' + id)
                  .then((res) => {
                    this.$message.success('批量完成成功');
                    this.$emit('closeDialog');
                    this.$store.commit('refreshDialog');
                  })
                  .catch((error) => {
                    try{
                      if (error.response&&error.response.data.msg) {
                        this.$message.error(error.response.data.msg);
                      } else {
                        this.$message.error('请求错误：' + error.response.status);
                      }
                    }catch (e) {
                      console.log(e);
                      this.$message.error('服务器错误');
                    }
                  });
            }else{
              let url = this.$larfree.replaceParm(event.url, {'id': id});
              this.$router.push(url);
            }
          }).catch(() => {});
        }
      }
    }
  }
}
